# Build recipe for guile.
#
# Copyright (C) 2017 MMPG, <mmpg@vp.pl>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

program=guile
version=2.2.2
release=1

tarname=${program}-${version}.tar.lz

# Remote source(s)
fetch=http://ftp.gnu.org/pub/gnu/guile/$tarname

description="
Project GNU's extension language library.

Guile is an implementation of the Scheme programming language, packaged
as a library that can be linked into applications to give them their own
extension language.  Guile supports other languages as well, giving
users of Guile-based applications a choice of languages.
"

homepage=https://www.gnu.org/software/guile/
license=GPLv3+

# Source documentation
docs="ABOUT-NLS AUTHORS ChangeLog COPYING COPYING.LESSER GUILE-VERSION HACKING LICENSE NEWS README THANKS TODO"
docsdir="${docdir}/${program}-${version}"

build()
{
    set -e
    unpack "${tardir}/$tarname"
    
    cd "$srcdir"
    
    ./configure CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
    $configure_args \
    --libdir=/usr/lib${libSuffix} \
    --infodir=$infodir \
    --mandir=$mandir \
    --docdir=$docdir \
    --build="$(cc -dumpmachine)"

    make -j${jobs}
    make -j${jobs} html
    
    makeinfo --plaintext -o doc/r5rs/r5rs.txt doc/r5rs/r5rs.texi
    makeinfo --plaintext -o doc/ref/guile.txt doc/ref/guile.texi
    
    
    make -j${jobs} DESTDIR="$destdir" install
    make -j${jobs} DESTDIR="$destdir" install-html
    
    # Move libguile*-gdb.scm to GDB's autoload directory to avoid getting "not an ELF file" errors from ldconfig
    mv /usr/lib/libguile-*-gdb.scm /usr/share/gdb/auto-load/usr/lib
    
    # Copy documentation
    mkdir -p "${destdir}${docsdir}"
    
    for file in $docs
    do
	cp -p $file "${destdir}${docsdir}"
    done
}
